<!--#Include File="conn.asp" -->
<!--#Include File="include/inc.asp"-->
<%
'====================================================================
'= Team Elite - Elite Article System
'= Copyright (c) 2005 - 2006 Eason Chan All Rights Reserved.
'=-------------------------------------------------------------------
'= 版权协议：
'=	GPL (The GNU GENERAL PUBLIC LICENSE Version 2, June 1991)
'=-------------------------------------------------------------------
'= 文件名称：Search.asp
'= 摘    要：搜索文件
'=-------------------------------------------------------------------
'= 最后更新：eason007
'= 最后日期：2006-02-07
'====================================================================

Dim Action
Action=Request.QueryString ("action")

Select Case LCase(Action)
Case "query"
	Call Request_Query()
Case Else
	Call Main()
End Select
Call EA_Pub.Close_Obj
Set EA_Pub=Nothing

Sub Request_Query()
	Dim KeyWord,ColumnId,Types,StartDate,EndTime,IsInclude
	Dim FieldName(6),FieldValue(6)
	Dim PageNum,PageSize,PageCount,ReCount,Column
	Dim i,WSQL
	Dim QueryArray,QueryList
	Dim PageContent
	Dim ConfigParameterArray
	Dim SQL
	
	PageNum=EA_Pub.SafeRequest(1,"page",0,1,0)
	
	KeyWord=EA_Pub.SafeRequest(1,"keyword",1,"",0)
	Column=EA_Pub.SafeRequest(1,"column",1,"0|",0)
	Column=Split(Column,"|")
	If UBound(Column)<>1 Then Column=Split("0|","|")
	Column(0)=EA_Pub.SafeRequest(0,Column(0),0,0,0)
	Column(1)=EA_Pub.SafeRequest(0,Column(1),1,"",0)
	Types=EA_Pub.SafeRequest(1,"field",0,0,0)
	StartDate=EA_Pub.SafeRequest(1,"stime",2,"1900-1-1",0)
	EndTime=EA_Pub.SafeRequest(1,"etime",2,FormatDateTime(Now()+1,2),0)
	IsInclude=EA_Pub.SafeRequest(1,"isinclude",0,0,0)
	PageSize=20

	If KeyWord="" And Column(0)=0 And StartDate="1900-1-1" And CStr(EndTime)=CStr(FormatDateTime(Now()+1,2)) Then 
		Call Main()
		Exit Sub
	End If
	
	FieldName(0)="keyword"
	FieldName(1)="column"
	FieldName(2)="field"
	FieldName(3)="stime"
	FieldName(4)="etime"
	FieldName(5)="isinclude"
	FieldName(6)="action"
	
	FieldValue(0)=KeyWord
	FieldValue(1)=Join(Column,"|")
	FieldValue(2)=Types
	FieldValue(3)=StartDate
	FieldValue(4)=EndTime
	FieldValue(5)=IsInclude
	FieldValue(6)="query"
	
	If iDataBaseType=0 Then
		WSQL="Where IsPass="&EA_DBO.TrueValue&" And IsDel=0 And AddDate Between #"&StartDate&"# And #"&EndTime&"# "
	Else
		WSQL="Where IsPass="&EA_DBO.TrueValue&" And IsDel=0 And AddDate Between '"&StartDate&"' And '"&EndTime&"' "
	End If
	Select Case Types
	Case 1
		WSQL=WSQL&MakeSQLQuery("keyword",KeyWord)
	Case 2
		WSQL=WSQL&MakeSQLQuery("Author",KeyWord)
	Case 3
		WSQL=WSQL&MakeSQLQuery("Summary",KeyWord)
	Case Else
		WSQL=WSQL&MakeSQLQuery("Title",KeyWord)
	End Select
	
	If Column(0)>0 Then 
		If IsInclude=1 Then 
			WSQL=WSQL&" And Left(ColumnCode,"&Len(Column(1))&")='"&Column(1)&"'"
		Else
			WSQL=WSQL&" And ColumnId="&Column(0)
		End If
	End If

	PageContent=EA_Temp.Load_Template(0,"search")
	
	'0=栏目1=文章类型标记2=发布时间3=作者4=点击5=浏览6=摘要
	ConfigParameterArray=EA_Temp.Find_TemplateTagValues("Config",PageContent)
	If Not IsArray(ConfigParameterArray) Then ConfigParameterArray=Split("1,1,1,0,0,0,1",",")

	SQL="Select Count([Id]) From [NB_Content] "&WSQL
	ReCount=EA_DBO.DB_Query(SQL)(0,0)
	PageCount=EA_Pub.Stat_Page_Total(PageSize,ReCount)
	If PageNum>PageCount And PageCount>0 Then PageNum=PageCount
	
	If PageCount>0 Then 
		WSQL = WSQL & " ORDER BY TrueTime DESC"
		SQL="Select [Id],ColumnId,ColumnName,IsImg,IsTop,TColor,Title,AddDate,Author,ViewNum,CommentNum,Summary From [NB_Content] "&WSQL
		QueryArray=EA_DBO.DB_CutPageQuery(SQL,PageNum,PageSize)
		If IsArray(QueryArray) Then 
			QueryList="<table border=""0"" align=""center"" cellpadding=""0"" cellspacing=""0"" width=""98%"" style=""word-break: break-all"">"
			For i=0 To UBound(QueryArray,2)
				QueryList=QueryList&"<tr>"
				QueryList=QueryList&"<td>&nbsp;"
				If ConfigParameterArray(0)="1" Then QueryList=QueryList&"[<a href="""&EA_Pub.Cov_ColumnPath(QueryArray(1,i),EA_Pub.SysInfo(18))&""" target=""_blank"">"&QueryArray(2,i)&"</a>]&nbsp;"
				If ConfigParameterArray(1)="1" Then QueryList=QueryList&EA_Pub.Chk_ArticleType(QueryArray(3,i),QueryArray(4,i))&"&nbsp;"
				QueryList=QueryList&"<a href="""&EA_Pub.Cov_ArticlePath(QueryArray(0,i),QueryArray(7,i),QueryArray(7,i),EA_Pub.SysInfo(18))&""" target=""_blank"">"&EA_Pub.Add_ArticleColor(QueryArray(5,i),QueryArray(6,i))&"</a>&nbsp;"
				If ConfigParameterArray(2)="1" Then QueryList=QueryList&""
				If ConfigParameterArray(3)="1" Then QueryList=QueryList&"(作者:"&QueryArray(8,i)&"&nbsp;"
				If ConfigParameterArray(4)="1" Then QueryList=QueryList&"浏览:"&QueryArray(9,i)&")&nbsp;"
				'If ConfigParameterArray(5)="1" Then QueryList=QueryList&"评论:"&QueryArray(10,i)&"&nbsp;"
				QueryList=QueryList&"</td>"
				QueryList=QueryList&"<td>"
				
				QueryList=QueryList&"[<font color=800000>"&FormatDate(QueryArray(7,i),2)&"</font>]&nbsp;"
				QueryList=QueryList&"</td>"
				QueryList=QueryList&"</tr>"
				If ConfigParameterArray(6)="1" Then
					QueryList=QueryList&"<tr>"
					QueryList=QueryList&"<td valign=""top"" align=""left"" bgcolor=""efefef"">"&QueryArray(11,i)&"</td>"
					QueryList=QueryList&"</tr>"
				End If
				QueryList=QueryList&"<tr>"
				QueryList=QueryList&"<td></td>"
				QueryList=QueryList&"</tr>"
			Next 
			
			QueryList=QueryList&"<tr>"
			QueryList=QueryList&"<td align=""right"" bgcolor=""efefef"">"&EA_Temp.PageList(PageCount,PageNum,FieldName,FieldValue)&"</td>"
			QueryList=QueryList&"</tr>"
			QueryList=QueryList&"</table>"
		End If
	Else
		QueryList="<table border=""0"" align=""center"" cellpadding=""0"" cellspacing=""0"" width=""98%"">"
		QueryList=QueryList&"<tr>"
		QueryList=QueryList&"<td height=""25"" align=""center"">暂无任何记录</td>"
		QueryList=QueryList&"</tr>"
		QueryList=QueryList&"</table>"
	End If
	
	EA_Temp.Title=EA_Pub.SysInfo(0)&" - 站点搜索"
	EA_Temp.Nav="<a href=""./""><b>"&EA_Pub.SysInfo(0)&"</b></a> - 搜索文章"

	PageContent=EA_Temp.Replace_PublicTag(PageContent)

	Call EA_Temp.Find_TemplateTagByInput("Config","",PageContent)
	
	PageContent=Replace(PageContent,"{$Query_List$}",QueryList)
	
	Response.Write PageContent
End Sub
'格式化日期
 '================================================
 '函数名：FormatDate
 '作  用：格式化日期
 '参  数：DateAndTime   ----原日期和时间
 '        para   ----日期格式
 '返回值：格式化后的日期
 '================================================
 Public Function FormatDate(datetime, para)
  On Error Resume Next
  Dim y, m, d, h, mi, s, strDateTime
  FormatDate = datetime
  If Not IsNumeric(para) Then Exit Function
  If Not IsDate(datetime) Then Exit Function
  y = CStr(Year(datetime))
  m = CStr(Month(datetime))
  If Len(m) = 1 Then m = "0" & m
  d = CStr(Day(datetime))
  If Len(d) = 1 Then d = "0" & d
  h = CStr(Hour(datetime))
  If Len(h) = 1 Then h = "0" & h
  mi = CStr(Minute(datetime))
  If Len(mi) = 1 Then mi = "0" & mi
  s = CStr(Second(DateAndTime))
  If Len(s) = 1 Then s = "0" & s
  select Case para
  Case "1"
   strDateTime = y & "-" & m & "-" & d & " " & h & ":" & mi & ":" & s
  Case "2"
   strDateTime = y & "-" & m & "-" & d
  Case "3"
   strDateTime = y & "/" & m & "/" & d
  Case "4"
   strDateTime = y & "年" & m & "月" & d & "日"
  Case "5"
   strDateTime = m & "-" & d
  Case "6"
   strDateTime = m & "/" & d
  Case "7"
   strDateTime = m & "月" & d & "日"
  Case "8"
   strDateTime = y & "年" & m & "月"
  Case "9"
   strDateTime = y & "-" & m
  Case "10"
   strDateTime = y & "/" & m
  Case "11"
   strDateTime = y & "." & m & "." & d

  Case Else
   strDateTime = datetime
  End select
  FormatDate = strDateTime
 End Function
 
Function MakeSQLQuery(QueryField,QueryStr)
	Dim TagStart,TagEnd
	Dim TempStr,TempArray
	Dim FullQueryStr
	Dim i,Way
	
	'先找引号定界符
	Do
		TagStart=InStr(QueryStr,"\")
		If TagStart>0 Then 
			TagEnd=InStr(TagStart+1,QueryStr,"\")
			
			TempStr=Mid(QueryStr,TagStart+1,TagEnd-TagStart-1)
			TempStr=Replace(TempStr," ","#")
			
			QueryStr=Left(QueryStr,TagStart-1)&TempStr&Right(QueryStr,Len(QueryStr)-TagEnd)
		End If
	Loop While TagStart>0
	
	'处理or定界符
	QueryStr=Replace(QueryStr,"|"," @")
	'分隔关键字
	TempArray=Split(QueryStr," ")
	
	For i=0 To UBound(TempArray)
		If Left(TempArray(i),1)="@" Then
			FullQueryStr=FullQueryStr&" Or "&QueryField
			TempArray(i)=Right(TempArray(i),Len(TempArray(i))-1)
		Else
			FullQueryStr=FullQueryStr&" And "&QueryField
		End If
		
		If Left(TempArray(i),1)="-" Then 
			FullQueryStr=FullQueryStr&" Not "
			TempArray(i)=Right(TempArray(i),Len(TempArray(i))-1)
		End If
		
		FullQueryStr=FullQueryStr&" Like '%"&TempArray(i)&"%'"
		
		FullQueryStr=Replace(FullQueryStr,"%$","")
		FullQueryStr=Replace(FullQueryStr,"$%","")
		FullQueryStr=Replace(FullQueryStr,"#"," ")
	Next
	
	MakeSQLQuery=FullQueryStr
End Function

Sub Main
	Dim ColumnArray,ColumnList
	Dim i,Level

	ColumnArray=EA_DBO.Get_Column_List()
	If IsArray(ColumnArray) Then 
		For i=0 To UBound(ColumnArray,2)
			Level=(Len(ColumnArray(2,i))/4-1)
			ColumnList=ColumnList&"<option value="""&ColumnArray(0,i)&"|"&ColumnArray(2,i)&""">"
			If Level>0 Then ColumnList=ColumnList&"├"
			ColumnList=ColumnList&String(Level,"-")
			ColumnList=ColumnList&ColumnArray(1,i)&"</option>"
		Next
	End If
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<meta http-equiv="Content-Language" content="zh-CN">
<meta name="keywords" content="<%=Replace(EA_Pub.SysInfo(16),"|",",")%>">
<meta name="Description" content="<%=EA_Pub.SysInfo(17)%>">
<meta name="generator" content="NB文章系统(NBArticle)">
<title><%=EA_Pub.SysInfo(0)%> - 站点搜索</title>
<script src="js/jsdate.js"></script>
<table width="762" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
  <form name="form1" method="post" action="?action=query">
    <tr> 
      <td bgcolor="#FFFFFF"> <table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
          <tr> 
            <td height="22" align="center" bgcolor="efefef">高 级 查 找</td>
          </tr>
          <tr> 
            <td height="20" align="center" bgcolor="#FFFFFF">搜索范围： 
              <input name="field" type="radio" value="0" checked>
              标题 
              <input type="radio" name="field" value="1">
              关键字 
              <input type="radio" name="field" value="2">
              作者 
              <input type="radio" name="field" value="3">
              摘要 </td>
          </tr>
          <tr> 
            <td height="20" align="center" bgcolor="#FFFFFF">关键字： 
              <input name="keyword" type="text" id="keyword"></td>
          </tr>
          <tr> 
            <td height="20" align="center" bgcolor="#FFFFFF">栏目分类： 
              <select name="column" class="iptA">
                <option value="0">--栏 目--</option>
                <%=ColumnList%>
              </select><input type="checkbox" name="isinclude" value="1">包含子栏目</td>
          </tr>
		  <tr> 
            <td height="20" align="center" bgcolor="#FFFFFF">开始时间：<input type="text" name="stime" size="10" readonly>&nbsp;<a href="#SelectDate" onClick="SD(this,'document.all.stime')"><img border="0" src="images/public/date_picker.gif" width="30" height="19" align="absmiddle"></a>&nbsp;&nbsp;结束时间：<input type="text" name="etime" size="10" readonly>&nbsp;<a href="#SelectDate" onClick="SD(this,'document.all.etime')"><img border="0" src="images/public/date_picker.gif" width="30" height="19" align="absmiddle"></a></td>
          </tr>
          <tr> 
            <td height="22" align="center" bgcolor="#FFFFFF"> <input type="submit" name="Submit" value="开始"> 
              <input type="reset" name="Submit2" value="重置"> </td>
          </tr>
        </table></td>
    </tr>
  </form>
</table>
<br>
<%
End Sub
%>
